﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class sitemanagement_MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["Username"] != null)
            {
                try
                {
                    lblName.Text = Session["Name"].ToString();
                    avatar.Src = Session["Avatar"].ToString();

                    if (Application["LastLog"] != null)
                    {
                        lblLastLogin.Text = Application["LastLog"].ToString();
                    }
                    else
                    {
                        lblLastLogin.Text = Session["LastLog"].ToString();
                    }
                }
                catch {}
            }

            try
            {
                if (Request.Cookies["HoangThinhCookie"] != null)
                {
                    HttpCookie myCookie = Request.Cookies.Get("HoangThinhCookie");
                    lblName.Text = myCookie.Values["Name"].ToString();
                    lblLastLogin.Text = myCookie.Values["LastLog"].ToString();
                    avatar.Src = myCookie.Values["Avatar"].ToString();
                }
            }
            catch { }
        }
    }

    protected void lbtLogout_Click(object sender, EventArgs e)
    {
        Application["ses"] = null;
        Session["Username"] = null;

        if ((Request.Cookies["HoangThinhCookie"] != null))
        {
            Response.Cookies["HoangThinhCookie"].Expires = DateTime.Now.AddDays(-1);
        }

        Application["LastLog"] = DateTime.Now.ToString("dd/MM/yyyy hh:mm");

        Response.Redirect("HTLogin.aspx");
    }
}
